package com.lx.oms.common.utils;

import org.apache.commons.configuration.Configuration;
import org.apache.commons.configuration.ConfigurationException;
import org.apache.commons.configuration.PropertiesConfiguration;

/**
 * 配置文件读取
 */
public class SftpSettingsUtil {

	private final static String configFile = "sftp.settings.properties";

	private final static String SFTP_HOST = "sftp.host";

	private final static String SFTP_PORT = "sftp.port";

	private final static String SFTP_USERNAME = "sftp.username";

	private final static String SFTP_PASSWORD = "sftp.password";

	private final static String IMAGESPATH_ARTICLE = "imagesPath.article";

	private final static String IMAGESPATH_DEMAND = "imagesPath.demand";

	private final static String IMAGESPATH_HEAD = "imagesPath.head";

	private final static String IMAGESPATH_PROJECT = "imagesPath.project";

	private final static String IMAGESPATH_TALK = "imagesPath.talk";

	private final static String IMAGESPATH_OTHER = "imagesPath.other";

	private final static String IMAGESPATH_QRCODE_HEAD = "imagesPath.qrcode.head";

	private final static String IMAGESPATH_QRCODE = "imagesPath.qrcode";

	private final static String ATTACHMENTSPATH_OTHER = "attachmentsPath.other";

	private final static String ATTACHMENTSPATH_SIGN = "attachmentsPath.sign";

	private final static String ATTACHMENTSPATH_PROPOSAL = "attachmentsPath.proposal";

	private static SftpSettingsUtil instance;
	private Configuration config;

	private SftpSettingsUtil() throws ConfigurationException {
		config = new PropertiesConfiguration(configFile);
	}

	public static synchronized SftpSettingsUtil getInstance() {
		if (instance == null) {
			try {
				instance = new SftpSettingsUtil();
			} catch (ConfigurationException e) {
				throw new RuntimeException(e);
			}
		}
		return instance;
	}

	/**
	 * 读取Integer类型配置
	 * @param key
	 * @return
	 */
	public Integer getInteger(String key) {
		return getInteger(key, 0);
	}
	
	public Integer getInteger(String key, int defaultValue) {
		return config.getInteger(key, defaultValue);
	}
	
	/**
	 * 读取String类型配置
	 * @param key
	 * @return
	 */
	public String getString(String key) {
		return config.getString(key);
	}

	/**
	 * 文件服务器地址
	 * @return
	 */
	public String getDefaultHost() {
		return getString(SFTP_HOST);
	}

	/**
	 * 文件服务器端口
	 * @return
	 */
	public Integer getDefaultPort() {
		return getInteger(SFTP_PORT);
	}

	/**
	 * 文件服务器登录帐号
	 * @return
	 */
	public String getDefaultUserName() {
		return getString(SFTP_USERNAME);
	}

	/**
	 * 文件服务器登录密码
	 * @return
	 */
	public String getDefaultPassword() {
		return getString(SFTP_PASSWORD);
	}

	/**
	 * 文章题图上传地址
	 * @return
	 */
	public String getArticleImagesPath() {
		return getString(IMAGESPATH_ARTICLE);
	}

	/**
	 * 需求题图上传地址
	 * @return
	 */
	public String getDemandImagesPath() {
		return getString(IMAGESPATH_DEMAND);
	}

	/**
	 * 用户头像上传地址
	 * @return
	 */
	public String getHeadImagesPath() {
		return getString(IMAGESPATH_HEAD);
	}

	/**
	 * 项目案例题图上传地址
	 * @return
	 */
	public String getProjectImagesPath() {
		return getString(IMAGESPATH_PROJECT);
	}

	/**
	 * 说说图片上传地址
	 * @return
	 */
	public String getTalkImagesPath() {
		return getString(IMAGESPATH_TALK);
	}

	/**
	 * 富文本图片上传地址
	 * @return
	 */
	public String getOtherImagesPath() {
		return getString(IMAGESPATH_OTHER);
	}

	/**
	 * 行业二维码头像图片上传地址
	 * @return
	 */
	public String getQrCodeHeadImagesPath() {
		return getString(IMAGESPATH_QRCODE_HEAD);
	}

	/**
	 * 行业二维码图片上传地址
	 * @return
	 */
	public String getQrCodeImagesPath() {
		return getString(IMAGESPATH_QRCODE);
	}

	/**
	 * 其它附件上传地址
	 * @return
	 */
	public String getOtherAttachmentsPath() {
		return getString(ATTACHMENTSPATH_OTHER);
	}

	/**
	 * 报名附件上传地址
	 * @return
	 */
	public String getSignAttachmentsPath() {
		return getString(ATTACHMENTSPATH_SIGN);
	}

	/**
	 * 提案附件上传地址
	 * @return
	 */
	public String getProposalAttachmentsPath() {
		return getString(ATTACHMENTSPATH_PROPOSAL);
	}
}
